package com.paraz.cst.impl;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import com.paraz.cst.CstException;
import com.paraz.cst.CstInput;

/**
 * CstInput that uses real input.
 * 
 * @author mparaz
 *
 */
public class RealCstInput implements CstInput {

	private final BufferedReader bufferedReader;
	
	RealCstInput(RealCstSocket socket) {
		InputStream inputStream;
		try {
			inputStream = socket.getSocket().getInputStream();
		} catch (IOException e) {
			throw new IllegalStateException("could not set up inputStream", e);
		}
		bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
	}
	
	public String read() throws CstException {
		try {
			return bufferedReader.readLine();
		} catch (IOException e) {
			throw new CstException(e);
		}
	}
}
